package com.situ.day3;

import java.util.Scanner;

import org.junit.Test;

public class ArrayDemo {

	@Test
	public void test1() {
		int[] array = new int[4];
		array[0] = 23;
		array[1] = 45;
		array[2] = 3;
		array[3] = 17;
		System.out.println(array[0]);
		System.out.println(array.length);
		System.out.println(array[array.length - 1]);
		System.out.println("--------------");
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		System.out.println("-------------");
		//逆序输出
		for (int i = array.length - 1; i >= 0; i--) {
			System.out.println(array[i]);
		}
	}
	
	@Test
	public void test2() {
		int[] array = new int[4];
		array[0] = 23;
		array[1] = 45;
		array[2] = 3;
		array[3] = 17;
		int sum = 0;
		for (int i = 0; i < array.length; i++) {
			//int num = array[i];
			//sum += num;
			sum += array[i];
		}
		System.out.println(sum);
	}
	
	@Test
	public void test3() {
		int[] array = new int[4];
		array[0] = 23;
		array[1] = 45;
		array[2] = 3;
		array[3] = 17;
		for (int i = 0; i <= array.length; i++) {
			System.out.println(array[i]);// array[4]
		}
	}
	
	@Test
	public void homework2() {
		int[] score = {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		
		int count = 0;
		for(int j = 0; j <= 9; j++) {// 10 
			for(int i = 0;i < score.length;i++) {// 30
				if (j ==  score[i]) {// 10*30=300
					count++;
				}
			}
			System.out.print(count + "  ");
			count = 0;
		}
	}
	
	@Test
	public void test22() {
		int[] scores = {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int[] countArray = new int[10];
		for (int i = 0; i < scores.length; i++) {
			switch (scores[i]) {
			case 0:
				countArray[0]++;
				break;
			case 1:
				countArray[1]++;
				break;
			case 2:
				countArray[2]++;
				break;
			case 3:
				countArray[3]++;
				break;
			default:
				break;
			}
		}
		//System.out.println("0出现的次数：" + countArray[0]);
		//System.out.println("1出现的次数：" + countArray[1]);
		for (int i = 0; i < countArray.length; i++) {
			System.out.println(i + "出现的次数：" + countArray[i]);
		}
	}
	
	@Test
	public void test244() {
		int[] score = {0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int jishuCount = 0;
		int oushuCount = 0;
		for (int i = 0; i < score.length; i++) {
			if (score[i] % 2 == 0) {
				jishuCount++;
			} else {
				oushuCount++;
			}
		}
		System.out.println("奇数个数：" + jishuCount);
		System.out.println("偶数个数：" + oushuCount);
	}

	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("情输入学生的个数");
		int num = scanner.nextInt();
		double[] array = new double[num];
		int sum = 0;
		for (int i = 0; i < array.length; i++) {
			System.out.println("请输入第" + (i + 1) + "个学生的成绩");
			array[i] = scanner.nextDouble();
			sum += array[i];
		}
		System.out.println("这" + num + "个学生的平均成绩是：" + sum / array.length);
	}

	@Test
	public void test44() {
		String str = "12321";
		char[]  array = str.toCharArray();
		for (int i = 0; i < array.length; i++) {
			System.out.print(array[i] + "\t");
		}
	}
	
	@Test
	public void test455() {
		System.out.println("请输入一个字符串：");
		Scanner scanner = new Scanner(System.in);
		String str = scanner.next();
		System.out.println(str);
	}
}
